home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / xfs / libxfs.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-04  |  24.0 KB  |  617 lines

  1. /*
  2.  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License as
  7.  * published by the Free Software Foundation.
  8.  *
  9.  * This program is distributed in the hope that it would be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write the Free Software Foundation,
  16.  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17.  */
  18. #ifndef __LIBXFS_H__
  19. #define __LIBXFS_H__
  20.  
  21. #define XFS_BIG_INUMS    1
  22. #define XFS_BIG_BLKNOS    1
  23.  
  24. #include <xfs/platform_defs.h>
  25.  
  26. #include <pthread.h>
  27. #include <xfs/list.h>
  28. #include <xfs/cache.h>
  29.  
  30. #include <xfs/xfs_fs.h>
  31. #include <xfs/xfs_types.h>
  32. #include <xfs/xfs_arch.h>
  33. #include <xfs/xfs_bit.h>
  34. #include <xfs/xfs_inum.h>
  35. #include <xfs/xfs_sb.h>
  36. #include <xfs/xfs_ag.h>
  37. #include <xfs/xfs_dir2.h>
  38. #include <xfs/xfs_mount.h>
  39. #include <xfs/xfs_da_btree.h>
  40. #include <xfs/xfs_bmap_btree.h>
  41. #include <xfs/xfs_alloc_btree.h>
  42. #include <xfs/xfs_ialloc_btree.h>
  43. #include <xfs/xfs_dir_sf.h>
  44. #include <xfs/xfs_dir2_sf.h>
  45. #include <xfs/xfs_attr_sf.h>
  46. #include <xfs/xfs_dinode.h>
  47. #include <xfs/xfs_inode.h>
  48. #include <xfs/xfs_buf_item.h>
  49. #include <xfs/xfs_inode_item.h>
  50. #include <xfs/xfs_alloc.h>
  51. #include <xfs/xfs_btree.h>
  52. #include <xfs/xfs_bmap.h>
  53.  
  54.  
  55. #ifndef XFS_SUPER_MAGIC
  56. #define XFS_SUPER_MAGIC 0x58465342
  57. #endif
  58.  
  59. #define xfs_isset(a,i)    ((a)[(i)/(sizeof((a))*NBBY)] & (1<<((i)%(sizeof((a))*NBBY))))
  60.  
  61. /*
  62.  * Argument structure for libxfs_init().
  63.  */
  64. typedef struct {
  65.                 /* input parameters */
  66.     char            *volname;       /* pathname of volume */
  67.     char            *dname;         /* pathname of data "subvolume" */
  68.     char            *logname;       /* pathname of log "subvolume" */
  69.     char            *rtname;        /* pathname of realtime "subvolume" */
  70.     int             isreadonly;     /* filesystem is only read in applic */
  71.     int             isdirect;       /* we can attempt to use direct I/O */
  72.     int             disfile;        /* data "subvolume" is a regular file */
  73.     int             dcreat;         /* try to create data subvolume */
  74.     int             lisfile;        /* log "subvolume" is a regular file */
  75.     int             lcreat;         /* try to create log subvolume */
  76.     int             risfile;        /* realtime "subvolume" is a reg file */
  77.     int             rcreat;         /* try to create realtime subvolume */
  78.     int        setblksize;    /* attempt to set device blksize */
  79.     int        usebuflock;    /* lock xfs_buf_t's - for MT usage */
  80.                 /* output results */
  81.     dev_t           ddev;           /* device for data subvolume */
  82.     dev_t           logdev;         /* device for log subvolume */
  83.     dev_t           rtdev;          /* device for realtime subvolume */
  84.     long long       dsize;          /* size of data subvolume (BBs) */
  85.     long long       logBBsize;      /* size of log subvolume (BBs) */
  86.                     /* (blocks allocated for use as
  87.                      * log is stored in mount structure) */
  88.     long long       logBBstart;     /* start block of log subvolume (BBs) */
  89.     long long       rtsize;         /* size of realtime subvolume (BBs) */
  90.     int        dbsize;        /* data subvolume device blksize */
  91.     int        lbsize;        /* log subvolume device blksize */
  92.     int        rtbsize;    /* realtime subvolume device blksize */
  93.     int             dfd;            /* data subvolume file descriptor */
  94.     int             logfd;          /* log subvolume file descriptor */
  95.     int             rtfd;           /* realtime subvolume file descriptor */
  96. } libxfs_init_t;
  97.  
  98. #define LIBXFS_EXIT_ON_FAILURE    0x0001    /* exit the program if a call fails */
  99. #define LIBXFS_ISREADONLY    0x0002    /* disallow all mounted filesystems */
  100. #define LIBXFS_ISINACTIVE    0x0004    /* allow mounted only if mounted ro */
  101. #define LIBXFS_DANGEROUSLY    0x0008    /* repairing a device mounted ro    */
  102. #define LIBXFS_EXCLUSIVELY    0x0010    /* disallow other accesses (O_EXCL) */
  103. #define LIBXFS_DIRECT        0x0020    /* can use direct I/O, not buffered */
  104.  
  105. extern char    *progname;
  106. extern int    libxfs_init (libxfs_init_t *);
  107. extern void    libxfs_destroy (void);
  108. extern int    libxfs_device_to_fd (dev_t);
  109. extern dev_t    libxfs_device_open (char *, int, int, int);
  110. extern void    libxfs_device_zero (dev_t, xfs_daddr_t, uint);
  111. extern void    libxfs_device_close (dev_t);
  112. extern int    libxfs_device_alignment (void);
  113. extern void    libxfs_report(FILE *);
  114.  
  115. /* check or write log footer: specify device, log size in blocks & uuid */
  116. typedef xfs_caddr_t (libxfs_get_block_t)(xfs_caddr_t, int, void *);
  117.  
  118. extern int    libxfs_log_clear (dev_t, xfs_daddr_t, uint, uuid_t *,
  119.                 int, int, int);
  120. extern int    libxfs_log_header (xfs_caddr_t, uuid_t *, int, int, int,
  121.                 libxfs_get_block_t *, void *);
  122.  
  123.  
  124. /*
  125.  * Define a user-level mount structure with all we need
  126.  * in order to make use of the numerous XFS_* macros.
  127.  */
  128. struct xfs_inode;
  129. typedef struct xfs_mount {
  130.     xfs_sb_t        m_sb;        /* copy of fs superblock */
  131.     char            *m_fsname;    /* filesystem name */
  132.     int            m_bsize;    /* fs logical block size */
  133.     xfs_agnumber_t        m_agfrotor;    /* last ag where space found */
  134.     xfs_agnumber_t        m_agirotor;    /* last ag dir inode alloced */
  135.     xfs_agnumber_t        m_maxagi;    /* highest inode alloc group */
  136.     uint            m_rsumlevels;    /* rt summary levels */
  137.     uint            m_rsumsize;    /* size of rt summary, bytes */
  138.     struct xfs_inode    *m_rbmip;    /* pointer to bitmap inode */
  139.     struct xfs_inode    *m_rsumip;    /* pointer to summary inode */
  140.     struct xfs_inode    *m_rootip;    /* pointer to root directory */
  141.     dev_t            m_dev;
  142.     dev_t            m_logdev;
  143.     dev_t            m_rtdev;
  144.     __uint8_t        m_dircook_elog;    /* log d-cookie entry bits */
  145.     __uint8_t        m_blkbit_log;    /* blocklog + NBBY */
  146.     __uint8_t        m_blkbb_log;    /* blocklog - BBSHIFT */
  147.     __uint8_t        m_sectbb_log;    /* sectorlog - BBSHIFT */
  148.     __uint8_t        m_agno_log;    /* log #ag's */
  149.     __uint8_t        m_agino_log;    /* #bits for agino in inum */
  150.     __uint16_t        m_inode_cluster_size;/* min inode buf size */
  151.     uint            m_blockmask;    /* sb_blocksize-1 */
  152.     uint            m_blockwsize;    /* sb_blocksize in words */
  153.     uint            m_blockwmask;    /* blockwsize-1 */
  154.     uint            m_alloc_mxr[2];    /* XFS_ALLOC_BLOCK_MAXRECS */
  155.     uint            m_alloc_mnr[2];    /* XFS_ALLOC_BLOCK_MINRECS */
  156.     uint            m_bmap_dmxr[2];    /* XFS_BMAP_BLOCK_DMAXRECS */
  157.     uint            m_bmap_dmnr[2];    /* XFS_BMAP_BLOCK_DMINRECS */
  158.     uint            m_inobt_mxr[2];    /* XFS_INOBT_BLOCK_MAXRECS */
  159.     uint            m_inobt_mnr[2];    /* XFS_INOBT_BLOCK_MINRECS */
  160.     uint            m_ag_maxlevels;    /* XFS_AG_MAXLEVELS */
  161.     uint            m_bm_maxlevels[2]; /* XFS_BM_MAXLEVELS */
  162.     uint            m_in_maxlevels;    /* XFS_IN_MAXLEVELS */
  163.     xfs_perag_t        *m_perag;    /* per-ag accounting info */
  164.     uint            m_flags;    /* global mount flags */
  165.     uint            m_qflags;    /* quota status flags */
  166.     uint            m_attroffset;    /* inode attribute offset */
  167.     uint            m_dir_node_ents; /* #entries in a dir danode */
  168.     uint            m_attr_node_ents; /* #entries in attr danode */
  169.     int            m_ialloc_inos;    /* inodes in inode allocation */
  170.     int            m_ialloc_blks;    /* blocks in inode allocation */
  171.     int            m_litino;    /* size of inode union area */
  172.     int            m_inoalign_mask;/* mask sb_inoalignmt if used */
  173.     xfs_trans_reservations_t m_reservations;/* precomputed res values */
  174.     __uint64_t        m_maxicount;    /* maximum inode count */
  175.     int            m_dalign;    /* stripe unit */
  176.     int            m_swidth;    /* stripe width */
  177.     int            m_sinoalign;    /* stripe unit inode alignmnt */
  178.     int            m_attr_magicpct;/* 37% of the blocksize */
  179.     int            m_dir_magicpct;    /* 37% of the dir blocksize */
  180.     __uint8_t        m_dirversion;    /* 1 or 2 */
  181.     const struct xfs_nameops *m_dirnameops;    /* vector of dir name ops */
  182.     int            m_dirblksize;    /* directory block sz--bytes */
  183.     int            m_dirblkfsbs;    /* directory block sz--fsbs */
  184.     xfs_dablk_t        m_dirdatablk;    /* blockno of dir data v2 */
  185.     xfs_dablk_t        m_dirleafblk;    /* blockno of dir non-data v2 */
  186.     xfs_dablk_t        m_dirfreeblk;    /* blockno of dirfreeindex v2 */
  187. } xfs_mount_t;
  188. #define    XFS_DIR_IS_V1(mp)    ((mp)->m_dirversion == 1)
  189. #define    XFS_DIR_IS_V2(mp)    ((mp)->m_dirversion == 2)
  190.  
  191. #define LIBXFS_MOUNT_ROOTINOS        0x0001
  192. #define LIBXFS_MOUNT_DEBUGGER        0x0002
  193. #define LIBXFS_MOUNT_32BITINODES    0x0004
  194. #define LIBXFS_MOUNT_32BITINOOPT    0x0008
  195. #define LIBXFS_MOUNT_COMPAT_ATTR    0x0010
  196.  
  197. #define LIBXFS_IHASHSIZE(sbp)        (1<<10)
  198. #define LIBXFS_BHASHSIZE(sbp)         (1<<10)
  199.  
  200. extern xfs_mount_t    *libxfs_mount (xfs_mount_t *, xfs_sb_t *,
  201.                 dev_t, dev_t, dev_t, int);
  202. extern void    libxfs_mount_common (xfs_mount_t *, xfs_sb_t *);
  203. extern xfs_agnumber_t    libxfs_initialize_perag (xfs_mount_t *, xfs_agnumber_t);
  204. extern int    libxfs_initialize_perag_data (xfs_mount_t *, xfs_agnumber_t);
  205. extern void    libxfs_umount (xfs_mount_t *);
  206. extern int    libxfs_rtmount_init (xfs_mount_t *);
  207. extern void    libxfs_rtmount_destroy (xfs_mount_t *);
  208. extern void    libxfs_alloc_compute_maxlevels (xfs_mount_t *);
  209. extern void    libxfs_bmap_compute_maxlevels (xfs_mount_t *, int);
  210. extern void    libxfs_ialloc_compute_maxlevels (xfs_mount_t *);
  211. extern void    libxfs_trans_init (xfs_mount_t *);
  212.  
  213.  
  214. /*
  215.  * Simple I/O interface
  216.  */
  217. typedef struct xfs_buf {
  218.     struct cache_node    b_node;
  219.     unsigned int        b_flags;
  220.     xfs_daddr_t        b_blkno;
  221.     unsigned        b_bcount;
  222.     dev_t            b_dev;
  223.     pthread_mutex_t        b_lock;
  224.     void            *b_fsprivate;
  225.     void            *b_fsprivate2;
  226.     void            *b_fsprivate3;
  227.     char            *b_addr;
  228. #ifdef XFS_BUF_TRACING
  229.     struct list_head    b_lock_list;
  230.     const char        *b_func;
  231.     const char        *b_file;
  232.     int            b_line;
  233. #endif
  234. } xfs_buf_t;
  235.  
  236. enum xfs_buf_flags_t {    /* b_flags bits */
  237.     LIBXFS_B_EXIT        = 0x0001,    /* ==LIBXFS_EXIT_ON_FAILURE */
  238.     LIBXFS_B_DIRTY        = 0x0002,    /* buffer has been modified */
  239.     LIBXFS_B_STALE        = 0x0004,    /* buffer marked as invalid */
  240.     LIBXFS_B_UPTODATE    = 0x0008    /* buffer is sync'd to disk */
  241. };
  242.  
  243. #define XFS_BUF_PTR(bp)            ((bp)->b_addr)
  244. #define xfs_buf_offset(bp, offset)    (XFS_BUF_PTR(bp) + (offset))
  245. #define XFS_BUF_ADDR(bp)        ((bp)->b_blkno)
  246. #define XFS_BUF_SIZE(bp)        ((bp)->b_bcount)
  247. #define XFS_BUF_COUNT(bp)        ((bp)->b_bcount)
  248. #define XFS_BUF_TARGET(bp)        ((bp)->b_dev)
  249. #define XFS_BUF_SET_PTR(bp,p,cnt)    ((bp)->b_addr = (char *)(p)); \
  250.                         XFS_BUF_SET_COUNT(bp,cnt)
  251. #define XFS_BUF_SET_ADDR(bp,blk)    ((bp)->b_blkno = (blk))
  252. #define XFS_BUF_SET_COUNT(bp,cnt)    ((bp)->b_bcount = (cnt))
  253.  
  254. #define XFS_BUF_FSPRIVATE(bp,type)    ((type)(bp)->b_fsprivate)
  255. #define XFS_BUF_SET_FSPRIVATE(bp,val)    (bp)->b_fsprivate = (void *)(val)
  256. #define XFS_BUF_FSPRIVATE2(bp,type)    ((type)(bp)->b_fsprivate2)
  257. #define XFS_BUF_SET_FSPRIVATE2(bp,val)    (bp)->b_fsprivate2 = (void *)(val)
  258. #define XFS_BUF_FSPRIVATE3(bp,type)    ((type)(bp)->b_fsprivate3)
  259. #define XFS_BUF_SET_FSPRIVATE3(bp,val)    (bp)->b_fsprivate3 = (void *)(val)
  260.  
  261. #define XFS_BUF_SET_PRIORITY(bp,pri)    cache_node_set_priority( \
  262.                         libxfs_bcache, \
  263.                         (struct cache_node *)(bp), \
  264.                         (pri))
  265. #define XFS_BUF_PRIORITY(bp)        (cache_node_get_priority( \
  266.                         (struct cache_node *)(bp)))
  267.  
  268. /* Buffer Cache Interfaces */
  269.  
  270. extern struct cache    *libxfs_bcache;
  271. extern struct cache_operations    libxfs_bcache_operations;
  272.  
  273. #ifdef XFS_BUF_TRACING
  274.  
  275. #define libxfs_readbuf(dev, daddr, len, flags) \
  276.         libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, (dev), (daddr), (len), (flags))
  277. #define libxfs_writebuf(buf, flags) \
  278.         libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, (buf), (flags))
  279. #define libxfs_getbuf(dev, daddr, len) \
  280.         libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, (dev), (daddr), (len))
  281. #define libxfs_putbuf(buf) \
  282.         libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
  283.  
  284. extern xfs_buf_t *libxfs_trace_readbuf(const char *, const char *, int, dev_t, xfs_daddr_t, int, int);
  285. extern int    libxfs_trace_writebuf(const char *, const char *, int, xfs_buf_t *, int);
  286. extern xfs_buf_t *libxfs_trace_getbuf(const char *, const char *, int, dev_t, xfs_daddr_t, int);
  287. extern void    libxfs_trace_putbuf (const char *, const char *, int, xfs_buf_t *);
  288.  
  289. #else
  290.  
  291. extern xfs_buf_t *libxfs_readbuf(dev_t, xfs_daddr_t, int, int);
  292. extern int    libxfs_writebuf(xfs_buf_t *, int);
  293. extern xfs_buf_t *libxfs_getbuf(dev_t, xfs_daddr_t, int);
  294. extern void    libxfs_putbuf (xfs_buf_t *);
  295.  
  296. #endif
  297.  
  298. extern xfs_buf_t *libxfs_getsb(xfs_mount_t *, int);
  299. extern void    libxfs_bcache_purge(void);
  300. extern void    libxfs_bcache_flush(void);
  301. extern void    libxfs_purgebuf(xfs_buf_t *);
  302. extern int    libxfs_bcache_overflowed(void);
  303. extern int    libxfs_bcache_usage(void);
  304.  
  305. /* Buffer (Raw) Interfaces */
  306. extern xfs_buf_t *libxfs_getbufr(dev_t, xfs_daddr_t, int);
  307. extern void    libxfs_putbufr(xfs_buf_t *);
  308.  
  309. extern int    libxfs_writebuf_int(xfs_buf_t *, int);
  310. extern int    libxfs_readbufr(dev_t, xfs_daddr_t, xfs_buf_t *, int, int);
  311.  
  312. extern int libxfs_bhash_size;
  313. extern int libxfs_ihash_size;
  314.  
  315. #define LIBXFS_BREAD    0x1
  316. #define LIBXFS_BWRITE    0x2
  317. #define LIBXFS_BZERO    0x4
  318.  
  319. extern void    libxfs_iomove (xfs_buf_t *, uint, int, void *, int);
  320.  
  321.  
  322. /*
  323.  * Transaction interface
  324.  */
  325.  
  326. typedef struct xfs_log_item {
  327.     struct xfs_log_item_desc    *li_desc;    /* ptr to current desc*/
  328.     struct xfs_mount        *li_mountp;    /* ptr to fs mount */
  329.     uint                li_type;    /* item type */
  330. } xfs_log_item_t;
  331.  
  332. typedef struct xfs_inode_log_item {
  333.     xfs_log_item_t        ili_item;        /* common portion */
  334.     struct xfs_inode    *ili_inode;        /* inode pointer */
  335.     unsigned short        ili_flags;        /* misc flags */
  336.     unsigned int        ili_last_fields;    /* fields when flushed*/
  337.     xfs_inode_log_format_t    ili_format;        /* logged structure */
  338. } xfs_inode_log_item_t;
  339.  
  340. typedef struct xfs_buf_log_item {
  341.     xfs_log_item_t        bli_item;    /* common item structure */
  342.     struct xfs_buf        *bli_buf;    /* real buffer pointer */
  343.     unsigned int        bli_flags;    /* misc flags */
  344.     unsigned int        bli_recur;    /* recursion count */
  345.     xfs_buf_log_format_t    bli_format;    /* in-log header */
  346. } xfs_buf_log_item_t;
  347.  
  348. #include <xfs/xfs_trans.h>
  349.  
  350. typedef struct xfs_trans {
  351.     unsigned int    t_type;            /* transaction type */
  352.     unsigned int    t_log_res;        /* amt of log space resvd */
  353.     unsigned int    t_log_count;        /* count for perm log res */
  354.     xfs_mount_t    *t_mountp;        /* ptr to fs mount struct */
  355.     unsigned int    t_flags;        /* misc flags */
  356.     long        t_icount_delta;        /* superblock icount change */
  357.     long        t_ifree_delta;        /* superblock ifree change */
  358.     long        t_fdblocks_delta;    /* superblock fdblocks chg */
  359.     long        t_frextents_delta;    /* superblock freextents chg */
  360.     unsigned int    t_items_free;        /* log item descs free */
  361.     xfs_log_item_chunk_t    t_items;    /* first log item desc chunk */
  362. } xfs_trans_t;
  363.  
  364. extern xfs_trans_t    *libxfs_trans_alloc (xfs_mount_t *, int);
  365. extern xfs_trans_t    *libxfs_trans_dup (xfs_trans_t *);
  366. extern int    libxfs_trans_reserve (xfs_trans_t *, uint,uint,uint,uint,uint);
  367. extern int    libxfs_trans_commit (xfs_trans_t *, uint, xfs_lsn_t *);
  368. extern void    libxfs_trans_cancel (xfs_trans_t *, int);
  369. extern void    libxfs_mod_sb (xfs_trans_t *, __int64_t);
  370. extern xfs_buf_t    *libxfs_trans_getsb (xfs_trans_t *, xfs_mount_t *, int);
  371.  
  372. extern int    libxfs_trans_iget (xfs_mount_t *, xfs_trans_t *, xfs_ino_t,
  373.                 uint, uint, struct xfs_inode **);
  374. extern void    libxfs_trans_iput(xfs_trans_t *, struct xfs_inode *, uint);
  375. extern void    libxfs_trans_ijoin (xfs_trans_t *, struct xfs_inode *, uint);
  376. extern void    libxfs_trans_ihold (xfs_trans_t *, struct xfs_inode *);
  377. extern void    libxfs_trans_log_inode (xfs_trans_t *, struct xfs_inode *,
  378.                 uint);
  379.  
  380. extern void    libxfs_trans_brelse (xfs_trans_t *, struct xfs_buf *);
  381. extern void    libxfs_trans_binval (xfs_trans_t *, struct xfs_buf *);
  382. extern void    libxfs_trans_bjoin (xfs_trans_t *, struct xfs_buf *);
  383. extern void    libxfs_trans_bhold (xfs_trans_t *, struct xfs_buf *);
  384. extern void    libxfs_trans_log_buf (xfs_trans_t *, struct xfs_buf *,
  385.                 uint, uint);
  386. extern xfs_buf_t    *libxfs_trans_get_buf (xfs_trans_t *, dev_t,
  387.                 xfs_daddr_t, int, uint);
  388. extern int    libxfs_trans_read_buf (xfs_mount_t *, xfs_trans_t *, dev_t,
  389.                 xfs_daddr_t, int, uint, struct xfs_buf **);
  390.  
  391.  
  392. /*
  393.  * Simple memory interface
  394.  */
  395. typedef struct xfs_zone {
  396.     int    zone_unitsize;    /* Size in bytes of zone unit           */
  397.     char    *zone_name;    /* tag name                             */
  398.     int    allocated;    /* debug: How many currently allocated  */
  399. } xfs_zone_t;
  400.  
  401. extern xfs_zone_t    *libxfs_zone_init (int, char *);
  402. extern void    *libxfs_zone_zalloc (xfs_zone_t *);
  403. extern void    libxfs_zone_free (xfs_zone_t *, void *);
  404. extern void    *libxfs_malloc (size_t);
  405. extern void    libxfs_free (void *);
  406. extern void    *libxfs_realloc (void *, size_t);
  407.  
  408.  
  409. /*
  410.  * Inode interface
  411.  */
  412. typedef struct xfs_inode {
  413.     struct cache_node    i_node;
  414.     xfs_mount_t        *i_mount;    /* fs mount struct ptr */
  415.     xfs_ino_t        i_ino;        /* inode number (agno/agino) */
  416.     xfs_daddr_t        i_blkno;    /* blkno of inode buffer */
  417.     dev_t            i_dev;        /* dev for this inode */
  418.     ushort            i_len;        /* len of inode buffer */
  419.     ushort            i_boffset;    /* off of inode in buffer */
  420.     xfs_ifork_t        *i_afp;        /* attribute fork pointer */
  421.     xfs_ifork_t        i_df;        /* data fork */
  422.     xfs_trans_t        *i_transp;    /* ptr to owning transaction */
  423.     xfs_inode_log_item_t    *i_itemp;    /* logging information */
  424.     unsigned int        i_delayed_blks;    /* count of delay alloc blks */
  425.     xfs_dinode_core_t    i_d;        /* most of ondisk inode */
  426. } xfs_inode_t;
  427.  
  428. #define LIBXFS_ATTR_ROOT    0x0002    /* use attrs in root namespace */
  429. #define LIBXFS_ATTR_SECURE    0x0008    /* use attrs in security namespace */
  430. #define LIBXFS_ATTR_CREATE    0x0010    /* create, but fail if attr exists */
  431. #define LIBXFS_ATTR_REPLACE    0x0020    /* set, but fail if attr not exists */
  432.  
  433. typedef struct cred {
  434.     uid_t    cr_uid;
  435.     gid_t    cr_gid;
  436. } cred_t;
  437.  
  438. extern int    libxfs_inode_alloc (xfs_trans_t **, xfs_inode_t *, mode_t,
  439.                 nlink_t, xfs_dev_t, struct cred *,
  440.                 struct fsxattr *, xfs_inode_t **);
  441. extern void    libxfs_trans_inode_alloc_buf (xfs_trans_t *, xfs_buf_t *);
  442.  
  443. extern void    libxfs_idata_realloc (xfs_inode_t *, int, int);
  444. extern void    libxfs_idestroy_fork (xfs_inode_t *, int);
  445. extern int    libxfs_iformat (xfs_inode_t *, xfs_dinode_t *);
  446. extern void    libxfs_ichgtime (xfs_inode_t *, int);
  447. extern int    libxfs_iflush_int (xfs_inode_t *, xfs_buf_t *);
  448. extern int    libxfs_itobp (xfs_mount_t *, xfs_trans_t *, xfs_inode_t *,
  449.                 xfs_dinode_t **, xfs_buf_t **, xfs_daddr_t);
  450. extern int    libxfs_iread (xfs_mount_t *, xfs_trans_t *, xfs_ino_t,
  451.                 xfs_inode_t *, xfs_daddr_t);
  452.  
  453. /* Inode Cache Interfaces */
  454. extern struct cache    *libxfs_icache;
  455. extern struct cache_operations    libxfs_icache_operations;
  456. extern void    libxfs_icache_purge (void);
  457. extern int    libxfs_iget (xfs_mount_t *, xfs_trans_t *, xfs_ino_t,
  458.                 uint, xfs_inode_t **, xfs_daddr_t);
  459. extern void    libxfs_iput (xfs_inode_t *, uint);
  460.  
  461.  
  462. /*
  463.  * Directory interface
  464.  */
  465. #include <xfs/xfs_dir_leaf.h>
  466. #include <xfs/xfs_dir2_data.h>
  467. #include <xfs/xfs_dir2_leaf.h>
  468. #include <xfs/xfs_dir2_block.h>
  469. #include <xfs/xfs_dir2_node.h>
  470.  
  471. extern void    libxfs_dir_mount (xfs_mount_t *);
  472. extern void    libxfs_dir2_mount (xfs_mount_t *);
  473. extern int    libxfs_dir_init (xfs_trans_t *, xfs_inode_t *, xfs_inode_t *);
  474. extern int    libxfs_dir2_init (xfs_trans_t *, xfs_inode_t *, xfs_inode_t *);
  475. extern int    libxfs_dir_createname (xfs_trans_t *, xfs_inode_t *, uchar_t *,
  476.                 int, xfs_ino_t, xfs_fsblock_t *,
  477.                 xfs_bmap_free_t *, xfs_extlen_t);
  478. extern int    libxfs_dir2_createname (xfs_trans_t *, xfs_inode_t *, uchar_t *,
  479.                 int, xfs_ino_t, xfs_fsblock_t *,
  480.                 xfs_bmap_free_t *, xfs_extlen_t);
  481. extern int    libxfs_dir_lookup (xfs_trans_t *, xfs_inode_t *,
  482.                 uchar_t *, int, xfs_ino_t *);
  483. extern int    libxfs_dir2_lookup (xfs_trans_t *, xfs_inode_t *,
  484.                 uchar_t *, int, xfs_ino_t *);
  485. extern int    libxfs_dir_replace (xfs_trans_t *, xfs_inode_t *,
  486.                 uchar_t *, int, xfs_ino_t, xfs_fsblock_t *,
  487.                 xfs_bmap_free_t *, xfs_extlen_t);
  488. extern int    libxfs_dir2_replace (xfs_trans_t *, xfs_inode_t *,
  489.                 uchar_t *, int, xfs_ino_t, xfs_fsblock_t *,
  490.                 xfs_bmap_free_t *, xfs_extlen_t);
  491. extern int    libxfs_dir_removename (xfs_trans_t *, xfs_inode_t *,
  492.                 uchar_t *, int, xfs_ino_t, xfs_fsblock_t *,
  493.                 xfs_bmap_free_t *, xfs_extlen_t);
  494. extern int    libxfs_dir2_removename (xfs_trans_t *, xfs_inode_t *,
  495.                 uchar_t *, int, xfs_ino_t, xfs_fsblock_t *,
  496.                 xfs_bmap_free_t *, xfs_extlen_t);
  497. extern int    libxfs_dir_bogus_removename (xfs_trans_t *, xfs_inode_t *,
  498.                 uchar_t *, xfs_fsblock_t *, xfs_bmap_free_t *,
  499.                 xfs_extlen_t, xfs_dahash_t, int);
  500. extern int    libxfs_dir2_bogus_removename (xfs_trans_t *, xfs_inode_t *,
  501.                 uchar_t *, xfs_fsblock_t *, xfs_bmap_free_t *,
  502.                 xfs_extlen_t, xfs_dahash_t, int);
  503.  
  504.  
  505. /*
  506.  * Block map interface
  507.  */
  508. extern int    libxfs_bmapi (xfs_trans_t *, xfs_inode_t *, xfs_fileoff_t,
  509.                 xfs_filblks_t, int, xfs_fsblock_t *,
  510.                 xfs_extlen_t, xfs_bmbt_irec_t *, int *,
  511.                 xfs_bmap_free_t *);
  512. extern int    libxfs_bmapi_single(xfs_trans_t *, xfs_inode_t *, int,
  513.                 xfs_fsblock_t *, xfs_fileoff_t);
  514. extern int    libxfs_bmap_finish (xfs_trans_t **, xfs_bmap_free_t *,
  515.                 xfs_fsblock_t, int *);
  516. extern void    libxfs_bmap_cancel(xfs_bmap_free_t *);
  517. extern int    libxfs_bmap_next_offset (xfs_trans_t *, xfs_inode_t *,
  518.                 xfs_fileoff_t *, int);
  519. extern int    libxfs_bmap_last_offset(xfs_trans_t *, xfs_inode_t *,
  520.                 xfs_fileoff_t *, int);
  521. extern int    libxfs_bunmapi (xfs_trans_t *, xfs_inode_t *, xfs_fileoff_t,
  522.                 xfs_filblks_t, int, xfs_extnum_t,
  523.                 xfs_fsblock_t *, xfs_bmap_free_t *, int *);
  524. extern void    libxfs_bmap_del_free (xfs_bmap_free_t *,
  525.                 xfs_bmap_free_item_t *, xfs_bmap_free_item_t *);
  526.  
  527.  
  528. /*
  529.  * All other routines we want to keep common...
  530.  */
  531.  
  532. extern int    libxfs_highbit32 (__uint32_t);
  533. extern int    libxfs_highbit64 (__uint64_t);
  534. extern uint    libxfs_da_log2_roundup (uint);
  535.  
  536. extern void    libxfs_xlate_sb (void *, xfs_sb_t *, int, __int64_t);
  537. extern void    libxfs_xlate_dinode_core (xfs_caddr_t buf,
  538.                 xfs_dinode_core_t *, int);
  539.  
  540. extern int    libxfs_alloc_fix_freelist (xfs_alloc_arg_t *, int);
  541. extern int    libxfs_alloc_file_space (xfs_inode_t *, xfs_off_t,
  542.                 xfs_off_t, int, int);
  543.  
  544. extern xfs_dahash_t    libxfs_da_hashname (const uchar_t *, int);
  545. extern int    libxfs_attr_leaf_newentsize (int, int, int, int *);
  546. extern int    libxfs_attr_set_int (xfs_inode_t*, const char *, int, char *,
  547.                 int, int);
  548. extern int    libxfs_attr_remove_int (xfs_inode_t *, const char *, int, int);
  549.  
  550.  
  551. extern void    libxfs_bmbt_get_all (xfs_bmbt_rec_t *, xfs_bmbt_irec_t *);
  552. #if __BYTE_ORDER != __BIG_ENDIAN
  553. extern void    libxfs_bmbt_disk_get_all (xfs_bmbt_rec_t *, xfs_bmbt_irec_t *);
  554. #else
  555. # define libxfs_bmbt_disk_get_all(r,s)    libxfs_bmbt_get_all(r,s)
  556. #endif
  557.  
  558. extern int    libxfs_free_extent (xfs_trans_t *, xfs_fsblock_t, xfs_extlen_t);
  559. extern int    libxfs_rtfree_extent (xfs_trans_t *, xfs_rtblock_t,
  560.                 xfs_extlen_t);
  561.  
  562. /* Directory/Attribute routines used by xfs_repair */
  563. extern void    libxfs_da_bjoin (xfs_trans_t *, xfs_dabuf_t *);
  564. extern int    libxfs_da_shrink_inode (xfs_da_args_t *, xfs_dablk_t,
  565.                 xfs_dabuf_t *);
  566. extern int    libxfs_da_grow_inode (xfs_da_args_t *, xfs_dablk_t *);
  567. extern void    libxfs_da_bhold (xfs_trans_t *, xfs_dabuf_t *);
  568. extern void    libxfs_da_brelse (xfs_trans_t *, xfs_dabuf_t *);
  569. extern int    libxfs_da_read_bufr (xfs_trans_t *, xfs_inode_t *, xfs_dablk_t,
  570.                 xfs_daddr_t, xfs_dabuf_t **, int);
  571. extern int    libxfs_da_read_buf (xfs_trans_t *, xfs_inode_t *,
  572.                 xfs_dablk_t, xfs_daddr_t, xfs_dabuf_t **, int);
  573. extern int    libxfs_da_get_buf (xfs_trans_t *, xfs_inode_t *,
  574.                 xfs_dablk_t, xfs_daddr_t, xfs_dabuf_t **, int);
  575. extern void    libxfs_da_log_buf (xfs_trans_t *, xfs_dabuf_t *, uint, uint);
  576. extern int    libxfs_dir2_shrink_inode (xfs_da_args_t *, xfs_dir2_db_t,
  577.                 xfs_dabuf_t *);
  578. extern int    libxfs_dir2_grow_inode (xfs_da_args_t *, int, xfs_dir2_db_t *);
  579. extern int    libxfs_dir2_isleaf (xfs_trans_t *, xfs_inode_t *, int *);
  580. extern int    libxfs_dir2_isblock (xfs_trans_t *, xfs_inode_t *, int *);
  581. extern void    libxfs_dir2_data_use_free (xfs_trans_t *, xfs_dabuf_t *,
  582.                 xfs_dir2_data_unused_t *, xfs_dir2_data_aoff_t,
  583.                 xfs_dir2_data_aoff_t, int *, int *);
  584. extern void    libxfs_dir2_data_make_free (xfs_trans_t *, xfs_dabuf_t *,
  585.                 xfs_dir2_data_aoff_t, xfs_dir2_data_aoff_t,
  586.                 int *, int *);
  587. extern void    libxfs_dir2_data_log_entry (xfs_trans_t *, xfs_dabuf_t *,
  588.                 xfs_dir2_data_entry_t *);
  589. extern void    libxfs_dir2_data_log_header (xfs_trans_t *, xfs_dabuf_t *);
  590. extern void    libxfs_dir2_data_freescan (xfs_mount_t *, xfs_dir2_data_t *,
  591.                 int *, char *);
  592. extern void    libxfs_dir2_free_log_bests (xfs_trans_t *, xfs_dabuf_t *,
  593.                 int, int);
  594.  
  595. /* Shared utility routines */
  596. extern unsigned int    libxfs_log2_roundup(unsigned int i);
  597.  
  598. extern void cmn_err(int, char *, ...);
  599. enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
  600.  
  601.  
  602. #define LIBXFS_BBTOOFF64(bbs)    (((xfs_off_t)(bbs)) << BBSHIFT)
  603. extern int        libxfs_nproc(void);
  604. extern unsigned long    libxfs_physmem(void);    /* in kilobytes */
  605.  
  606. #include <xfs/xfs_ialloc.h>
  607. #include <xfs/xfs_rtalloc.h>
  608.  
  609. #include <xfs/xfs_attr_leaf.h>
  610. #include <xfs/xfs_quota.h>
  611. #include <xfs/xfs_trans_space.h>
  612. #include <xfs/xfs_imap.h>
  613. #include <xfs/xfs_log.h>
  614. #include <xfs/xfs_log_priv.h>
  615.  
  616. #endif    /* __LIBXFS_H__ */
  617.